﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TestXNA3.Components;
using System.Runtime.Serialization;

namespace TestXNA3.Actors
{
    [Serializable]
    public class PointLight : Light
    {
        private float _radius;
        [System.ComponentModel.Category("Light")]
        public float Radius
        {
            get { return _radius; }
            set { _radius = value; }
        }

        protected override void duplicateProperties(Actor a)
        {
            base.duplicateProperties(a);
            PointLight l = a as PointLight;
            l.Radius = Radius;
        }

        public PointLight()
        {
            AttachComponent(new PointLightComponent());

            if (GameStartup.InEditor)
            {
                _spriteComponent = new SpriteComponent();
                _spriteComponent.Texture = new TestXNA3.Resources.TextureResource("Lightbulb");
                AttachComponent(_spriteComponent);
            }
        }

        public override void Save(System.IO.BinaryWriter writer)
        {
            base.Save(writer);
            writer.Write(Radius);
        }

        public override void Load(System.IO.BinaryReader reader)
        {
            DetachComponent(Components[0]);
            base.Load(reader);
            Radius = reader.ReadSingle();

            if (GameStartup.InEditor)
            {
                _spriteComponent = new SpriteComponent();
                _spriteComponent.Texture = new TestXNA3.Resources.TextureResource("Lightbulb");
                AttachComponent(_spriteComponent);
            }
        }

        public override void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            base.GetObjectData(info, context);

            info.AddValue("Radius", Radius);
        }
    }
}
